<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        div{
            width: 500px;
            height: 400px;
            border: 10px solid red;
            position: relative;
        }
        img{
            position: absolute;
            top: 0px;
        }
    </style>
</head>
<body>
    <div id="box">
        <img id="star" src="img/star.png">
    </div>
    <script>
        var t = 0; // 最开始的top
        var timer;

        timer = setInterval(function(){
            // 让星星掉下来   img.style.top 逐渐增加
            t+=3
            star.style.top= t + 'px'
            // 如果掉地上了，就让星星不要继续往下了
            if (t > 336) {
                clearInterval(timer)
            }
        },30)
        box.onclick = function() {
            t -= 30
        }
    </script>
</body>
</html>